// 爆款商品渲染
$.get(' http://www.xiongmaoyouxuan.com/api/column/baokuan?start=0', function (result) {
    let productlist = result.data.list
    console.log(productlist);
    let data = { productlist }
    $('.mainHeard').html(template('productlist', data))
})
// 商品导航栏渲染
$.get('http://www.xiongmaoyouxuan.com/api/tabs?sa=', function (result) {
    let listName = result.data.list
    listName.splice(0, 1)
    let data = { listName }
    $('.swiper-wrapper1').html(template("listName", data))
})
// 导航轮播
var mySwiper = new Swiper('.bannerFont', {
    slidesPerView: 6,
    spaceBetween: 10,
    pagination: {
        clickable: true,
    }
})
// banner轮播
var mySwiper = new Swiper('.bannerMain', {
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    speed: 500,
    autoplay: {
        delay: 2000
    },
    // 自动播放  
    autoplay: true,
    effect: 'fade',
    fadeEffect: {
        crossFade: true,
    },
})
// 商品详情页
function commodityDetails(index) {
    location.href = 'commodityDetails.html?id=' + index
}
$('.shop').on("click", function () {
    window.open('shopcart.html')
})
// 回到顶部
var timer = null;
box.onclick = function () {
    cancelAnimationFrame(timer);
    timer = requestAnimationFrame(function fn() {
        var oTop = document.body.scrollTop || document.documentElement.scrollTop;
        if (oTop > 0) {
            document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
            timer = requestAnimationFrame(fn);
        } else {
            cancelAnimationFrame(timer);
        }
    });
}
let pageNo = 0 // 页号
// 底部刷新
$(window).scroll(function () {
    let scrollTop = $(this).scrollTop(); //滚动条距离顶部的高度
    let  scrollHeight = $(document).height(); //当前页面的总高度
    let clientHeight = $(this).height(); //当前可视的页面高度
    if (scrollTop + clientHeight >= scrollHeight) { //距离顶部+当前高度 >=文档总高度 即代表滑动到底部 count++;         //每次滑动count加1
       
        pageNo++
        let str = 'http://www.xiongmaoyouxuan.com/api/column/baokuan?start=' + pageNo*20
        console.log(str)
        $.get(str, function (result) {
            console.log(result);
            let productlist1 = result.data.list
            console.log(productlist1);
            let str1 = ``
            productlist1.forEach(item => {
                str1 += `
                <div class="commodity" onclick="commodityDetails(${item.id})">
                    <div class="productImg">
                        <img src=${item.image} class="imgBig">
                    </div>
                    <div class="productDisc">
                        <p class="titleName">${item.title}</p>
                        <div class="commodityTip">
                            <img src=""
                                alt="">
                            <p>${item.dataoke.rankingTag}</p>
                        </div>
                        <p class="hot">全天热卖NO.${item.dataoke.dailyRanking}</p>
                        <div class="commodityPrice">
                            <span>券后￥</span>
                            <span class="theirPrice">${item.price}</span>
                            <span class="realPrice">￥${item.originPrice}</span>
                        </div>
                        <div class="coupon">
                            <div class="ticket">${item.couponValue}</div>
                            <div class="monthlySales">月销${item.dataoke.monthSales}</div>
                        </div>
                    </div>
                </div>
                `
            });
            console.log(str1);
            $('.mainHeard').append(str1)
            console.log($('.mainHeard').html());
        })
    }

});

// 到登陆页面
$('.me').on('click', function () {
    location.href = 'logIn.html'
})
// 好物
$(".rubbish").on('click', function () {
    alert('全是垃圾东西，没有好物')
})
// 首页
$('.bb').on("click", function () {
    alert('这里就是首页')
})